package com.xiezc.data.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xiezc.common.entity.Chapter;
import com.xiezc.common.result.PojoResult;
import com.xiezc.data.service.ChapterTextService;
import com.xiezc.common.entity.ChapterText;
import com.xiezc.common.result.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 章节内容 前端控制器
 * </p>
 *
 * @author xiezc
 * @since 2018-10-06
 */
@RestController
@RequestMapping("/chapterText")
public class ChapterTextController {

    @Resource
    ChapterTextService chapterTextService;

    @PostMapping("add")
    public BaseResult addChapter(@RequestBody ChapterText chapterText) {
        boolean save = chapterTextService.save(chapterText);
        return save ? BaseResult.success() : BaseResult.fail("500", "save error");
    }

    @GetMapping("getByUrl")
    public PojoResult<ChapterText> getByUrl(String url) {
        LambdaQueryWrapper<ChapterText> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ChapterText::getFetchUrl, url);
        ChapterText one = chapterTextService.getOne(wrapper);
        return PojoResult.success(one);
    }
}

